package com.ruoyi.threads;

/**
 * @Author syc
 * @Date Created in 16:11 2022/8/10
 * @Description
 */
// 多个线程同时操作一个对象
// 买火车票的例子
public class TeatThread4 implements  Runnable {

    // 票数
    private int ticketNums = 10;

    @Override
    public void run() {
        while (true) {
            if (ticketNums <= 0 ) {
                break;
            }
            // 模拟延时
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "-->拿到了第" + ticketNums--+"票" );
        }
    }

    public static void main(String[] args) {
        TeatThread4 teatThread4 = new TeatThread4();
        new Thread(teatThread4, "小明").start();
        new Thread(teatThread4, "老师").start();
        new Thread(teatThread4, "黄牛党").start();
    }


}
